package com.bupt.controller;

import com.bupt.bean.ChannelDirection;
import com.bupt.config.DirectionResult;
import com.bupt.config.Result;
import com.bupt.dao.SectionRepository;
import com.bupt.service.DirectionService;
import com.bupt.vo.ChannelDirectionVo;
import com.bupt.vo.SysConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value="通道地理位置接口",description="通道下地理位置的增删改查、地理位置方向")
@RestController
public class DirectionController {

    @Autowired
    private SectionRepository sectionRepository;

    @Autowired
    private DirectionService directionService;



    @ApiOperation("通过设备通道ID查询通道的地理位信息")
    @GetMapping("/direction/channelDirectionById/{deviceChannelId}")
    public List<ChannelDirectionVo> channelSectionById(@PathVariable("deviceChannelId") Integer deviceChannelId) {
        return directionService.channelDirectionById(deviceChannelId);

    }


    @ApiOperation("通道地理位信息添加页面")
    @PostMapping("/direction/add")
    public DirectionResult add(@RequestParam("deviceChannelId") Integer deviceChannelId, @RequestParam("position") Float position, @RequestParam("longitude") String longitude, @RequestParam("latitude") String latitude) {
        return directionService.add(deviceChannelId, position,longitude,latitude);
    }


    @ApiOperation("删除通道下的某个地理位置信息")
    @DeleteMapping("/direction/deleteById/{channelDirectionId}")
    public Result deleteById(@PathVariable("channelDirectionId") Integer channelDirectionId) {
        return directionService.deleteById(channelDirectionId);
    }

    @ApiOperation("通过IP修改单个地理位置信息")
    @PutMapping("/direction/edit/{deviceChannelId}/{channelDirectionId}")
    public DirectionResult editDirectionById(@PathVariable("deviceChannelId") Integer deviceChannelId,@PathVariable("channelDirectionId") Integer channelDirectionId, @RequestBody ChannelDirection channelDirection) {
        return directionService.editDirectionById(deviceChannelId,channelDirectionId, channelDirection);
    }


    @ApiOperation("地理位置方向")
    @GetMapping("/direction/channelDirection")
    public List<SysConst> channelDirection() {
        return directionService.channelDirection();

    }
}
